<template>
  <div class="app-container">
    <div class="main-content">
      <!-- 搜索表单 -->
      <el-card class="box-card">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
          <el-form-item label="车牌号" prop="vehicleName">
            <el-input
              v-model="queryParams.vehicleName"
              placeholder="请输入车牌号"
              clearable
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-select v-model="queryParams.status" placeholder="车辆状态" clearable style="width: 200px">
              <el-option label="正常" value="0" />
              <el-option label="停用" value="1" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>

      <!-- 操作按钮区域 -->
      <div class="action-buttons">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </div>

      <!-- 数据表格 -->
      <el-card class="box-card table-card">
        <el-table
          v-loading="loading"
          :data="deptList"
          border
          stripe
          style="width: 100%"
        >
          <el-table-column prop="vehicleName" label="车牌号" min-width="120"></el-table-column>
          <el-table-column prop="parkingName" label="停车场名称" min-width="120"></el-table-column>
          <el-table-column prop="status" label="状态" width="100">
            <template slot-scope="scope">
              <el-tag :type="scope.row.status === '0' ? 'success' : 'info'">
                {{ scope.row.status === '0' ? '正常' : '停用' }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="创建时间" align="center" prop="createTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="200">
            <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改</el-button>
              <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </div>
  </div>
</template>

<script>
import { listparking } from "@/api/parking/parking";
import { parseTime } from '@/utils';

export default {
  name: "StopTheCar",
  data() {
    return {
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 表格数据
      deptList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        vehicleName: undefined,
        status: undefined
      }
    };
  },
  created() {
    this.getlistparking();
  },
  methods: {
    parseTime,
    /** 查询列表 */
    getlistparking() {
      this.loading = true;
      listparking(this.queryParams).then(response => {
        console.log('API返回数据:', response);
        this.deptList = response.data.records || [];
        this.loading = false;
      }).catch(error => {
        console.error('获取数据失败:', error);
        this.loading = false;
        this.$message.error('获取数据失败');
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getlistparking();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push('/parking/add');
    },
    /** 表单重置 */
    resetForm(refName) {
      if (this.$refs[refName]) {
        this.$refs[refName].resetFields();
      }
    }
  }
};
</script>

<style scoped>
.app-container {
  padding: 20px;
  background-color: #f0f2f5;
  min-height: calc(100vh - 84px);
}

.main-content {
  max-width: 1200px;
  margin: 0 auto;
}

.box-card {
  margin-bottom: 20px;
  border-radius: 4px;
}

.table-card {
  margin-top: 20px;
}

.action-buttons {
  margin: 15px 0;
}

.el-form-item {
  margin-bottom: 10px;
  margin-right: 10px;
}

.el-button--text {
  padding: 0 8px;
}

.el-tag {
  margin-right: 8px;
}

.el-table {
  margin-top: 15px;
}

.el-card__body {
  padding: 20px;
}
</style>
